<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品订单</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
        <el-table
            :data="productList"
            stripe
            border
            style="width: 100%">

            <el-table-column
                prop="goods.name"
                label="商品名">
                <!-- <template slot-scope="scope">
                    <div>
                        {{scope.row.yard.yard.name}}
                    </div>
                </template> -->
            </el-table-column>
            <el-table-column
                prop="goods.price"
                label="商品价格（元）">
            </el-table-column>
            <el-table-column
                prop="number"
                label="购买数量">
            </el-table-column>
            <el-table-column
                prop="state"
                label="状态">
                <template slot-scope="scope">
                  <div v-if="scope.row.state==1">待支付</div>
                  <div v-else-if="scope.row.state==2">支付成功-待取货</div>
                  <div v-else-if="scope.row.state==3">交易关闭-已取</div>
                  <div v-else-if="scope.row.state==4">交易关闭-未取货</div>
                  <div v-else-if="scope.row.state==5">交易关闭-未付款</div>
                  <div v-else-if="scope.row.state==6">退款</div>
                </template>
            </el-table-column>
            <!-- <el-table-column
                prop="rent.message"
                label="留言">
            </el-table-column> -->
            <el-table-column
                prop="createTime"
                label="下单时间">
                <template slot-scope="scope">
                    <div>{{setDate(scope.row.createTime)}}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="verify"
                label="校验码">
            </el-table-column>
            <el-table-column
                label="操作">
                <template slot-scope="scope">
                    <div>
                       <!-- <el-button type="primary" @click="changeCommodity(scope.row)">修改</el-button>
                        <el-button type="danger" @click="delCommodity(scope.row)">删除</el-button> -->
                        <el-button v-if="scope.row.state==2" type="primary" @click="checkCommodity(scope.row,1)">校验</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
    data(){
        return{
            loading:false,
            dialogTitle:'',
            show:false,
            productList:[],

        }
    },
    async created(){
        this.getComputed()
    },
    methods:{
        async getComputed(){
            const { data } = await this.$http.get('venue/order?type=2')
            if (data.state !== 0) {
            return this.$message.error(data.msg)
            }
            this.productList = data.result.reduce((pre,item)=>{return pre.concat(item.goods)},[])
            console.log(this.productList)
        },
        async checkCommodity(item,type){
          console.log(item)
          const {data} = await this.$http.post('venue/verify/goods',{
            orderGoodsId: item.id,
            verify: item.verify
          })
          if (data.state !== 0) return this.$message.error(data.msg)
          this.getComputed()
          return this.$message.success(data.msg)
        },
        setDate(originValue) {
              const dt = new Date(originValue)
              const y = dt.getFullYear()
              // 月份，字符串不足两位以0填充
              const m = (dt.getMonth() + 1 + '').padStart(2, '0')
              const d = (dt.getDate() + '').padStart(2, '0')
              const hh = (dt.getHours() + '').padStart(2, '0')
              const mm = (dt.getMinutes() + '').padStart(2, '0')
              const ss = (dt.getSeconds() + '').padStart(2, '0')

              return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
          },
    }
}
</script>

<style>

</style>
